/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Forms;

import BLL.BLLBenhNhan;
import DTO.DTOBenhNhan;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author Documents
 */
public class DanhSachBenhNhan extends javax.swing.JFrame {
    BLLBenhNhan bllBenhNhan = new BLLBenhNhan();
    DefaultTableModel modelBenhNhan;
    /**
     * Creates new form DanhSachBenhNhan
     */
    public DanhSachBenhNhan() {
        initComponents();
        
        //lấy danh sách bệnh nhân
        modelBenhNhan = new DefaultTableModel();
        String[] cols = {"Mã BN", "Họ tên", "Giới tính", "Năm sinh", "CMND", "BHYT"};//tiêu đề cột
        modelBenhNhan.setColumnIdentifiers(cols);
        for(DTOBenhNhan dtoBenhNhan : bllBenhNhan.layDSBenhNhan()){
            modelBenhNhan.addRow(new Object[]{dtoBenhNhan.getMaBN(), dtoBenhNhan.getHoten(), dtoBenhNhan.getGioitinh(),
                                       dtoBenhNhan.getNgaysinh(), dtoBenhNhan.getCMND(), dtoBenhNhan.getBHYT()==1?"Có":"Không" });
        }
        //set model cho table bệnh nhân
        jTableDSBN.setModel(modelBenhNhan);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jpnlChiTiet = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtxtMaBN = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jtxtHoTen = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jtxtTuoi = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jtxtNgaySinh = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jtxtDiaChi = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jtxtCmnd = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jrabtnCo = new javax.swing.JRadioButton();
        jrabtnKhong = new javax.swing.JRadioButton();
        jtxtMaBH = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jLabel12 = new javax.swing.JLabel();
        jrabtnNam = new javax.swing.JRadioButton();
        jrabtnNu = new javax.swing.JRadioButton();
        jLabel10 = new javax.swing.JLabel();
        jtxtDienThoai = new javax.swing.JTextField();
        txtNgayHetHan = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jpnlTuyChon = new javax.swing.JPanel();
        jbtnXemHS = new javax.swing.JButton();
        jbtnThem = new javax.swing.JButton();
        jbtnSua = new javax.swing.JButton();
        jbtnXoa = new javax.swing.JButton();
        jpnlDanhSach = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTableDSBN = new javax.swing.JTable();
        jpnlTim = new javax.swing.JPanel();
        jtxtTim = new javax.swing.JTextField();
        jbtnTim = new javax.swing.JButton();
        btnReload = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setResizable(false);

        jpnlChiTiet.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(new java.awt.Color(255, 255, 255), new java.awt.Color(0, 0, 102)), "Thông tin chi tiết"));

        jLabel1.setText("Mã BN");

        jtxtMaBN.setEnabled(false);

        jLabel3.setText("Họ tên");

        jtxtHoTen.setEnabled(false);
        jtxtHoTen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtHoTenActionPerformed(evt);
            }
        });

        jLabel4.setText("Giới tính");

        jLabel5.setText("Năm sinh");

        jtxtTuoi.setEnabled(false);

        jLabel6.setText("CMND");

        jtxtNgaySinh.setEnabled(false);

        jLabel7.setText("Địa chỉ");

        jtxtDiaChi.setEnabled(false);

        jLabel8.setText("Tuổi");

        jtxtCmnd.setEnabled(false);

        jLabel9.setText("BHYT");

        buttonGroup2.add(jrabtnCo);
        jrabtnCo.setText("Có");
        jrabtnCo.setEnabled(false);

        buttonGroup2.add(jrabtnKhong);
        jrabtnKhong.setText("Không");
        jrabtnKhong.setEnabled(false);

        jtxtMaBH.setEnabled(false);

        jLabel11.setText("Mã BHYT");

        jCheckBox1.setText("Vượt tuyến");
        jCheckBox1.setEnabled(false);

        jLabel12.setText("Ngày hết hạn");

        buttonGroup1.add(jrabtnNam);
        jrabtnNam.setText("Nam");
        jrabtnNam.setEnabled(false);

        buttonGroup1.add(jrabtnNu);
        jrabtnNu.setText("Nữ");
        jrabtnNu.setEnabled(false);

        jLabel10.setText("Điện thoại");

        jtxtDienThoai.setEnabled(false);

        txtNgayHetHan.setEnabled(false);

        javax.swing.GroupLayout jpnlChiTietLayout = new javax.swing.GroupLayout(jpnlChiTiet);
        jpnlChiTiet.setLayout(jpnlChiTietLayout);
        jpnlChiTietLayout.setHorizontalGroup(
            jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5)
                    .addComponent(jLabel7)
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                        .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, 478, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlChiTietLayout.createSequentialGroup()
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlChiTietLayout.createSequentialGroup()
                                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                        .addComponent(jtxtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(24, 24, 24)
                                        .addComponent(jLabel8)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jtxtTuoi, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(2, 2, 2))
                                    .addComponent(jtxtMaBN))
                                .addGap(18, 18, 18)
                                .addComponent(jLabel3))
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addGap(196, 196, 196)
                                .addComponent(jLabel6)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jtxtCmnd, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlChiTietLayout.createSequentialGroup()
                                .addGap(39, 39, 39)
                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 65, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jrabtnNam, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jrabtnNu, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                                .addGap(18, 18, 18)
                                .addComponent(jLabel10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jtxtDienThoai)))
                        .addContainerGap())
                    .addGroup(jpnlChiTietLayout.createSequentialGroup()
                        .addComponent(jrabtnCo)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jrabtnKhong)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox1)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel11)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jtxtMaBH, javax.swing.GroupLayout.PREFERRED_SIZE, 151, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel12)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtNgayHetHan, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                        .addContainerGap(20, Short.MAX_VALUE))))
        );
        jpnlChiTietLayout.setVerticalGroup(
            jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlChiTietLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 19, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel3)
                        .addComponent(jtxtHoTen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jrabtnNu)
                        .addComponent(jtxtMaBN, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jrabtnNam)
                        .addComponent(jLabel4)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jtxtTuoi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6)
                    .addComponent(jtxtNgaySinh, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8)
                    .addComponent(jtxtCmnd, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10)
                    .addComponent(jtxtDienThoai, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel7)
                    .addComponent(jtxtDiaChi, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpnlChiTietLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jrabtnCo)
                    .addComponent(jrabtnKhong)
                    .addComponent(jtxtMaBH, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel11)
                    .addComponent(jCheckBox1)
                    .addComponent(jLabel12)
                    .addComponent(txtNgayHetHan, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        jLabel2.setForeground(new java.awt.Color(0, 102, 0));
        jLabel2.setText("DANH SÁCH BỆNH NHÂN");

        jpnlTuyChon.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 102)), "Tùy chọn"));

        jbtnXemHS.setText("Xem hồ sơ");
        jbtnXemHS.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXemHSActionPerformed(evt);
            }
        });

        jbtnThem.setText("Thêm mới");
        jbtnThem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnThemActionPerformed(evt);
            }
        });

        jbtnSua.setText("Sửa");
        jbtnSua.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnSuaActionPerformed(evt);
            }
        });

        jbtnXoa.setText("Xóa");
        jbtnXoa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnXoaActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnlTuyChonLayout = new javax.swing.GroupLayout(jpnlTuyChon);
        jpnlTuyChon.setLayout(jpnlTuyChonLayout);
        jpnlTuyChonLayout.setHorizontalGroup(
            jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlTuyChonLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jbtnXemHS, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnThem, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnSua, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jbtnXoa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jpnlTuyChonLayout.setVerticalGroup(
            jpnlTuyChonLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlTuyChonLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jbtnXemHS)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnThem)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jbtnSua)
                .addGap(10, 10, 10)
                .addComponent(jbtnXoa)
                .addContainerGap())
        );

        jpnlDanhSach.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 102)), "Danh sách bệnh nhân"));

        jTableDSBN.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jTableDSBN.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jTableDSBNMousePressed(evt);
            }
        });
        jScrollPane1.setViewportView(jTableDSBN);

        javax.swing.GroupLayout jpnlDanhSachLayout = new javax.swing.GroupLayout(jpnlDanhSach);
        jpnlDanhSach.setLayout(jpnlDanhSachLayout);
        jpnlDanhSachLayout.setHorizontalGroup(
            jpnlDanhSachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1)
        );
        jpnlDanhSachLayout.setVerticalGroup(
            jpnlDanhSachLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlDanhSachLayout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 259, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(90, 90, 90))
        );

        jpnlTim.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(null, new java.awt.Color(0, 0, 102)), "Tìm kiếm"));

        jtxtTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jtxtTimActionPerformed(evt);
            }
        });

        jbtnTim.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Icons/IconsLandVista.png"))); // NOI18N
        jbtnTim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtnTimActionPerformed(evt);
            }
        });

        btnReload.setText("Tải lại");
        btnReload.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnReloadActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jpnlTimLayout = new javax.swing.GroupLayout(jpnlTim);
        jpnlTim.setLayout(jpnlTimLayout);
        jpnlTimLayout.setHorizontalGroup(
            jpnlTimLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpnlTimLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jbtnTim, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jtxtTim, javax.swing.GroupLayout.PREFERRED_SIZE, 206, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnReload)
                .addContainerGap())
        );
        jpnlTimLayout.setVerticalGroup(
            jpnlTimLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpnlTimLayout.createSequentialGroup()
                .addGroup(jpnlTimLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpnlTimLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jtxtTim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(btnReload))
                    .addComponent(jbtnTim))
                .addGap(0, 3, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jpnlChiTiet, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnlTuyChon, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jpnlTim, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jpnlDanhSach, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addGap(285, 285, 285))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(18, Short.MAX_VALUE)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jpnlTuyChon, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpnlChiTiet, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnlTim, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpnlDanhSach, javax.swing.GroupLayout.PREFERRED_SIZE, 303, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, 0))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jtxtHoTenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtHoTenActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtHoTenActionPerformed

    private void jTableDSBNMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTableDSBNMousePressed
        try {
            clearField();
            String maBN = jTableDSBN.getValueAt(jTableDSBN.getSelectedRow(), 0).toString();
            DTOBenhNhan dtoBenhNhan = bllBenhNhan.layBNTheoMa(maBN);
            if(dtoBenhNhan != null){
                jtxtMaBN.setText(dtoBenhNhan.getMaBN());
                jtxtHoTen.setText(dtoBenhNhan.getHoten());
                jtxtDiaChi.setText(dtoBenhNhan.getDiachi());
                jtxtDienThoai.setText(dtoBenhNhan.getDienthoai());
                jtxtCmnd.setText(dtoBenhNhan.getCMND());
                jtxtMaBH.setText(dtoBenhNhan.getMaBH());
                jtxtNgaySinh.setText(dtoBenhNhan.getNgaysinh());
                if("Nam".equals(dtoBenhNhan.getGioitinh())){
                    jrabtnNam.setSelected(true);
                }
                else
                    jrabtnNu.setSelected(true);
                
                if(dtoBenhNhan.getBHYT()==1)
                    jrabtnCo.setSelected(true);
                else
                    jrabtnKhong.setSelected(true);
                
                if(dtoBenhNhan.getVuottuyen()==1)
                    jCheckBox1.setSelected(true);
                else
                    jCheckBox1.setSelected(false);
                if(dtoBenhNhan.getNgayhethan() != null)
                    txtNgayHetHan.setText(dtoBenhNhan.getNgayhethan().toString());
                
                SimpleDateFormat format = new SimpleDateFormat("yyyy");
                java.util.Date date = new java.util.Date();
                String currentYear = format.format(date);
                int tuoi = Integer.valueOf(currentYear) - Integer.valueOf(dtoBenhNhan.getNgaysinh());
                jtxtTuoi.setText(String.valueOf(tuoi));
            }
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Loi phat sinh, khong the lay thong tin nguoi dung");
        }
    }//GEN-LAST:event_jTableDSBNMousePressed

    private void clearField(){
        jtxtMaBN.setText("");
        jtxtHoTen.setText("");
        jtxtDiaChi.setText("");
        jtxtDienThoai.setText("");
        jtxtCmnd.setText("");
        jtxtMaBH.setText("");
        jtxtNgaySinh.setText("");
        txtNgayHetHan.setText("");
    }
    private void jbtnThemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnThemActionPerformed
        DangKyKhamBenh dk = new DangKyKhamBenh();
        Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
        dk.setLocation((dim.width - dk.getWidth())/2, (dim.height - dk.getHeight())/2);
        dk.setVisible(true);
    }//GEN-LAST:event_jbtnThemActionPerformed

    private void jbtnTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnTimActionPerformed
        try {
            for (int i = modelBenhNhan.getRowCount() -1; i >= 0; i--) {
                modelBenhNhan.removeRow(i);
            }
            String tim = jtxtTim.getText();
            ArrayList<DTOBenhNhan> dsBenhNhan = bllBenhNhan.timBenhNhan(tim);
            for(DTOBenhNhan dtoBenhNhan : dsBenhNhan){
                modelBenhNhan.addRow(new Object[]{dtoBenhNhan.getMaBN(), dtoBenhNhan.getHoten(), dtoBenhNhan.getGioitinh(),
                                       dtoBenhNhan.getNgaysinh(), dtoBenhNhan.getCMND(), dtoBenhNhan.getBHYT()==1?"Có":"Không" });
            }
        } catch (Exception e) {
        }
    }//GEN-LAST:event_jbtnTimActionPerformed

    private void jbtnSuaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnSuaActionPerformed
        try {
            String maBN = jTableDSBN.getValueAt(jTableDSBN.getSelectedRow(), 0).toString();
            if(maBN != null){
                SuaThongTinBenhNhan form = new SuaThongTinBenhNhan(maBN);
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                form.setLocation((dim.width - form.getWidth())/2, (dim.height - form.getHeight())/2);
                form.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(null, "Vui lòng chọn bệnh nhân cần sửa");
        } catch (Exception e) {
            JOptionPane.showMessageDialog(null, "Vui lòng chọn bệnh nhân cần sửa");
        }
    }//GEN-LAST:event_jbtnSuaActionPerformed

    private void btnReloadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnReloadActionPerformed
        for (int i = modelBenhNhan.getRowCount() -1; i >= 0; i--) {
                modelBenhNhan.removeRow(i);
            }
        for(DTOBenhNhan dtoBenhNhan : bllBenhNhan.layDSBenhNhan()){
            modelBenhNhan.addRow(new Object[]{dtoBenhNhan.getMaBN(), dtoBenhNhan.getHoten(), dtoBenhNhan.getGioitinh(),
                                       dtoBenhNhan.getNgaysinh(), dtoBenhNhan.getCMND(), dtoBenhNhan.getBHYT()==1?"Có":"Không" });
        }
    }//GEN-LAST:event_btnReloadActionPerformed

    private void jbtnXoaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXoaActionPerformed
        try {
            int[] dong = jTableDSBN.getSelectedRows();
            if(dong.length > 0){
                if(JOptionPane.showConfirmDialog(null, "Bạn có chắc muốn xóa?", "Thông báo", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE)==JOptionPane.YES_OPTION){
                    int dem = 0;
                    for(int i = dong.length - 1; i >= 0; i--){
                        String maBn = jTableDSBN.getValueAt(dong[i], 0).toString();
                        bllBenhNhan.xoaBenhNhan(maBn);
                        modelBenhNhan.removeRow(dong[i]);
                        dem++;
                    }
                    if(dem==dong.length){
                        JOptionPane.showMessageDialog(null, "Đã xóa các bệnh nhân thành công");
                    }
                }
            }
            else
                JOptionPane.showMessageDialog(null, "Vui lòng chọn mục muốn xóa");
        } catch (Exception e) {
        }
    }//GEN-LAST:event_jbtnXoaActionPerformed

    private void jtxtTimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtxtTimActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jtxtTimActionPerformed

    private void jbtnXemHSActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtnXemHSActionPerformed
         try {
            String maBN  = jTableDSBN.getValueAt(jTableDSBN.getSelectedRow(), 0).toString();
            if(maBN != null){
                HoSoKhamBenh form = new HoSoKhamBenh(maBN);
                Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
                form.setLocation((dim.width - form.getWidth())/2, (dim.height - form.getHeight())/2);
                form.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(null, "Chọn hồ sơ cần xem");
        } catch (Exception e) {
            //JOptionPane.showMessageDialog(null, "Vui long chon benh nhan can sua");
        }
    }//GEN-LAST:event_jbtnXemHSActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DanhSachBenhNhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DanhSachBenhNhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DanhSachBenhNhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DanhSachBenhNhan.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DanhSachBenhNhan().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnReload;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableDSBN;
    private javax.swing.JButton jbtnSua;
    private javax.swing.JButton jbtnThem;
    private javax.swing.JButton jbtnTim;
    private javax.swing.JButton jbtnXemHS;
    private javax.swing.JButton jbtnXoa;
    private javax.swing.JPanel jpnlChiTiet;
    private javax.swing.JPanel jpnlDanhSach;
    private javax.swing.JPanel jpnlTim;
    private javax.swing.JPanel jpnlTuyChon;
    private javax.swing.JRadioButton jrabtnCo;
    private javax.swing.JRadioButton jrabtnKhong;
    private javax.swing.JRadioButton jrabtnNam;
    private javax.swing.JRadioButton jrabtnNu;
    private javax.swing.JTextField jtxtCmnd;
    private javax.swing.JTextField jtxtDiaChi;
    private javax.swing.JTextField jtxtDienThoai;
    private javax.swing.JTextField jtxtHoTen;
    private javax.swing.JTextField jtxtMaBH;
    private javax.swing.JTextField jtxtMaBN;
    private javax.swing.JTextField jtxtNgaySinh;
    private javax.swing.JTextField jtxtTim;
    private javax.swing.JTextField jtxtTuoi;
    private javax.swing.JTextField txtNgayHetHan;
    // End of variables declaration//GEN-END:variables
}
